<?php
	echo $html->css ( 'tab' );
	echo $html->css ( 'jquery-validate/css/screen' );
	echo $html->css('flexigrid');
	echo $html->css('start/jquery-ui-1.8.2.custom');
	echo $javascript->link('flexigrid/flexigrid'); 
	echo $javascript->link('resourcebooks_add');
	//echo $javascript->link('DatePicker/WdatePicker');
	echo $javascript->link('jquery-ui-1.8.2.custom.min');
?>

<script language="javascript">
var delurl="<?php echo $deleteurl; ?>";
</script>
<script language="javascript">
var editurl="<?php echo $editurl; ?>";
</script>
<script language="javascript">
var addurl="<?php echo $addurl; ?>";
</script>
<script language="javascript">
var data=<?php echo $data; ?>;
</script>
<script language="javascript">
var disbutton=<?php echo $javascript->object($disbutton);?>;
</script>
<script language="javascript">
var title2="<?php echo $title2; ?>";
</script>
<script language="javascript">
function button(com,grid,url)  
{  
	var ids=$("#flex").getCheckedRows();
	if(com=="delete")
	{
		var pids="";
		if(ids.length==0)
		{
			alert("请选择你要删除的项");
			return;
		}
		if(!confirm("确定删除?"))
		{
			return;
		}
		for(i=0;i<ids.length;i++)
        {
        	pids=pids+ids[i]+"/";
        }

		$.ajax({
            type: "post",
            url: url,
            data: {id:pids},
            dataType:"json",
            success: function(data) {
            $(".clearckeck").trigger("click");
			$(".pReload").trigger("click");
			//$(".notice").html(data.message); 
			},
            error: function(data) {
				$(".clearckeck").trigger("click");
				$(".pReload").trigger("click");
				//$(".notice").html('data.message');
			}
        });
	}
	else if(com=="add")
	{
		window.open(url);
	}
	else if(com=="edit")
	{
		if(ids.length!=1)
		{
			alert("请选择一个选项");
		}
		
		else
		{
			var seid=ids[0];
			var eurl=url+"/"+seid;
			window.open(eurl);
		}
	}
	else
	{
		var pix=com.substring(0,2);
		switch (pix)
		{
			case "aj":
				var pids="";
				if(ids.length==0)
				{
					alert("请选择选项");
					return;
				}
				if(!confirm("确定强制结束?"))
				{
					return;
				}
				for(i=0;i<ids.length;i++)
		        {
		        	pids=pids+ids[i]+"/";
		        }
				$.ajax({
		           type: "post",
		           url: url,
		            data: {id:pids},
		            dataType:"json",
		            success: function(data) {
					$(".pReload").trigger("click");
					//$(".notice").html(data.message); 
					},
		            error: function(data) {
						$(".clearckeck").trigger("click");
						$(".pReload").trigger("click");
						//$(".notice").html('data.message');
					}
		        });
				break;
			case "up":
				if(ids.length!=1)
				{
					alert("请选择一个选项");
				}
				else
				{
					var seid=ids[0];
					var eurl=url+"?id="+seid;
					window.open(eurl);
				}
				break;
			default:
				window.open(url);
		}
	}
}
</script>
<script type="text/javascript">
var b=[];
</script>
<script type="text/javascript">
var ob=[];
if(ob.length==0)
{
	
}
else
{
	for(i=0;i<ob.length;i++)
	{
		var l=b.length;
		b[l]=ob[i];
	}
}
</script>

<script type="text/javascript">
	$(function(){
		$(".datepickerSpan :input").datepicker({
			inline: true
		});
		 $('.datepickerSpan :input').datepicker('option', {dateFormat: "yy-mm-dd"});
		 $('.datepickerSpan :input').datepicker( "option", "closeText", 'X' );
	});

//级联菜单 //
$(function() {
	$("#company").change(function(){
		var list = $(this).val();
		if(list!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/resourcebooks/getResource/",{
				Resource : $(this).val()
				},function(data,textStatus){
					 $("#position:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					 //alert($(this).attr("name"));
					 $("#position:eq(0)").append("<option></option>");
					 $("#position:eq(0)>option:last").val($(this).attr("name")).html($(this).text());				 
				 	 });
				});
			}
			else
			{
				$("#position:eq(0)>option").remove();
				$("#position:eq(0)").append("<option></option>");
				$("#position:eq(0)>option:last").val("").html("全部");
			}

	});
	$(".resetsubmit").click(function(){
		$("#position:eq(0)>option").remove();
		$("#position:eq(0)").append("<option></option>");
		$("#position:eq(0)>option:last").val("").html("全部");
	});
});
</script>

<script type="text/javascript">
//添加验证
$(document).ready(function() {
	$.validator.setDefaults({       
		 submitHandler: function(form) {    
		  form.submit();
  
		}     
	});   
			
	$("#ResourcebookAddForm").validate({
		rules: {
		"data[Resourcebook][title]"  :{
			required: true,alowsome:true,stringMinLength:1,stringMaxLength:50
			},//主题
			"data[Resourcebook][useage]"  :{
				required: false,stringMinLength:0,stringMaxLength:255
				},
			"data[Resourcebook][resource_id]"  :{
				required: true,selectNone:true
				}//设施必选	
		},
		messages:{
			"data[Resourcebook][resource_id]"  :{
				required: "请选择一个存在的设施"
				}//设施必选	
		},
		focusInvalid:false,
		onkeyup:false,
		errorPlacement:function(error, element){error.appendTo(element.parent());}
	});
});
//验证结束
</script>

<script type="text/javascript">
//级联菜单 //
$(function() {
	$("#ResourcebookOrganId").change(function(){
		var list = $(this).val();
		if(list!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/resourcebooks/getResource/",{
				Resource : $(this).val()
				},function(data,textStatus){
					 $("#ResourcebookResourceId:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					 $("#ResourcebookResourceId:eq(0)").append("<option></option>");
					 $("#ResourcebookResourceId:eq(0)>option:last").val($(this).attr("name")).html($(this).text());				 
				  });

				});
		}

	});
});
</script>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Resourcebooksmanage');//一级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('Add Resourcebooks',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->
 <?php echo $form->create('Resourcebook',array('action'=>'add','type'=>'post'));?>
<div class="tabflex">
<fieldset>
 	<legend><?php __('Add Resourcebooks');?></legend>
	<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">

	<tr>
		<td width="1%">
		<?php
					echo $form->hidden('creater');
					echo $form->hidden('updater');	?></td>
		<td width="10%"><?php __('subject');?>:<font color="red">*</font></td>
		<td width="30%"><?php echo $form->input('title',array('class' => 'TextBoxE1','label'=>false));?></td>
		<td width="5%"></td>
		<td width="10%"><?php __('ResourceSelect');?>:<font color="red">*</font></td>
		<td width="40%"> 
					<?php $options = array();
								foreach($organs as $eachrecord)
								{					
									$options[$eachrecord['Organ']['id']] = $eachrecord['Organ']['name'];
								}
								echo $form->input('organ_id',array('options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1','empty' =>'不限'));					
					//机构下拉菜单?>
					<?php $options1 = array();
								foreach($resource as $eachrecord)
								{					
									$options1[$eachrecord['Resource']['id']] = $eachrecord['Resource']['resourceName'];
								}
								echo $form->input('resource_id',array('options'=>$options1,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));
					//机构下资源（设施）下拉菜单?>
		</td>
	</tr>
	<tr>
		<td ></td>
		<td ><?php __('Creator');//创建人?>:</td>
		<td><?php echo $form->input('creater',array('disabled'=>'disabled','label'=>false,'class' => 'TextBoxE1','value'=>$creater));?>
		<?php echo $form->hidden('founder',array('value'=>$creater));?></td>
	
		<td ></td>
		<td ><?php __('Create_Time');//创建时间?>:</td>
		<td><?php echo $form->input('creationTime',array('label'=>false,'dateFormat'=>'YMD', 'monthNames' => false,'timeFormat'=> '24','disabled'=>'disabled'));?>
			<?php echo $form->hidden('founder',array('value'=>$creater));?></td>
	</tr>
	<tr>
		<td ></td>
		<td ><?php __('StartUseTime');//开始时间?>:</td>
		<td ><?php 
			echo $form->input('startTime',array('label'=>false,'dateFormat'=>'YMD','monthNames' => false, 'timeFormat'=> '24','id'=>'ee'));
		
		?></td>
		<td ></td>
		<td><?php __('EndUseTime');//结束时间?>:</td>
		<td><?php echo $form->input('endTime',array('label'=>false,'dateFormat'=>'YMD','monthNames' => false, 'timeFormat'=> '24'));?></td>
	</tr>
	<tr>
		<td></td>
		<td><?php __('ResourcebooksUser');//使用人?>:</td>
		<td colspan="4">
			<?php $options2 = array();
								foreach($users as $eachrecord)
								{					
									$options2[$eachrecord['User']['id']] = $eachrecord['User']['username'];
								}
								echo $form->input('user',array('options'=>$options2,'label'=>false,'div'=>false,'class'=>'TextBoxE1','empty' =>'请选择'));					
					//使用者选择下拉菜单?>
		</td>
	</tr>
	<tr>
		<td></td>
		<td ><?php __('ResourcebooksUseage');?>:</td>
		<td colspan="4">
		<?php echo $form->textarea('useage',array('class' => 'areaStyle','label'=>false));?>
		</td>
	</tr>
	</table>
	</fieldset>
</div>

<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('type'=>'submit','class'=>'btn2'));?> 
		</td>
		<td width="100"><?php echo $form->button('取消',array('type'=>'reset','class'=>'btn2'));?> 
		</td>
		<td width="100" id="tomanagebook" style="display:none;"><a href="<?php echo ROOT_WEB_PATH; ?>/resources/index" target="self">
			<?php echo $html->image('setting.gif',array('alt' =>  __('Add', true),'title'=>'设施定制','border'=>'0' )); ?>&nbsp;设施定制</a>
		</td>
	</tr>
</table>
<?php echo $form->end();?>

<div class="tabflex" style="text-align:left;margin-left:20px;">
<fieldset><legend>设施预定查询</legend>
<?php if (count($searchitems)>0)
{
	$j=0;
	echo "<form class='searchform'>";
	for ($i=0;$i<count($searchitems);$i++)
	{
		$item=$searchitems[$i];

		if ($item['type']=="text")
		{
			echo $item['lable']."<input type='text' name='".$item['name']."' class='sitems' id=".$item['id']."></input>";
		}
		elseif ($item['type']=="select")
		{
			echo $item['lable']."<select name='".$item['name']."' class='sitems' id=".$item['id'].">";
			foreach ($item['op'] as $k=>$v)
			{
				echo "<option value='$v'>$k</option>";
			}
			echo "</select>";
		}
		elseif ($item['type']=="checkbox")
		{
			echo "<input type='checkbox' name='".$item['name']."' class='sitems' id=".$item['id']. "value=".$item['value']." ></input>".$item['lable'];
		}
		elseif ($item['type']=="date")
		{
			echo $item['lable'];?><span class="datepickerSpan"><input type='text' name="<?php echo $item['name']?>" class='sitems' id="<?php echo $item['id'];?>"></input></span>
			
		<?php 
		}
		if ($item['br'])
		{
			echo "<br>";
		}
	}
}
echo "<br><input type='submit' class='btn2' value='查询'/>";
echo "</form>";
?>
</fieldset>
</div>
<!--                                                                           查询区域-->
<!--                                                                           表格-->
<div class="tabflex" id="tabflex" style="text-align:left;margin-left:20px;">
<table id="flex" style="display: none"></table><br></br>
</div>